const DB = wx.cloud.database()
let that
Page({
  data: {
    lianyuan_user:false,
    showModal:false
    // showModal:true
  },
  onLoad: function(options) {
    if(options.lianyuan){
      this.setData({
        lianyuan_user:true
      })
    }else{
      this.setData({
        lianyuan_user:false
      })
    }
    that = this
    this.setData({
      userInfo:wx.getStorageSync('userInfo')
    })
    DB.collection('character_list')
      .get({
        success: function(res) {
          let list = res.data
          console.log('list:', list)
          // list = getRandomArrayElements(list, 3)
          console.log('随机的list:', list)
          // list.forEach((value, i) => {
          // });
          that.setData({
            quest: list
          })
        }
      })
  },
  // 获取该组件的id
  radio: function(e) {
    this.setData({
      guige_key02: e.currentTarget.dataset.id
    })
    console.log(e.currentTarget.dataset.id)
  },
  radioChange: function(e) {
    this.setData({
      arr_guige02: e.detail.value
    })
    console.log(e.detail.value)
  },
  formSubmit: function (e) {
    var form_data = e.detail.value;
    console.log('form_data', e.detail.value)
    DB.collection('user').doc( wx.getStorageSync('userInfo')._id).update({
      data:{
        character_list: form_data
      }
    }).then(res=>{
      var userInfo = wx.getStorageSync('userInfo')
      userInfo.character_list =form_data
      wx.setStorageSync('userInfo', userInfo)
    
      if(!this.data.lianyuan_user){
        that.setData({
          showModal:true
        })
      }else{
        wx.reLaunch({
          url: '/pages/find/index',
        })
      }
  })
  },
  showCancelOrder: function() {
    this.setData({
      showModal:true
    })
  },
  modal_click_Hidden: function () {
    this.setData({
      showModal: false,
    })
  },
  // 确定
  Sure: function () {
    wx.switchTab({
      url: '/pages/find/index',
    })
  },
  onShow: function() {

  },

  onShareAppMessage: function () {
    var res = {
      path: "/pages/user_detail/user_detail?openid=" + wx.getStorageSync('userInfo')._openid + '&share=true',
      success: function (e) {},
      // title: getApp().share_title || null,
      imageUrl:wx.getStorageSync('userInfo').userInfoDetail.hande
    };
    return res;
  },
})